package com.market.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.market.domain.transients.DAY_OF_WEEK;

@Entity
@Table(name = "pickupschedule")
public class PickupSchedule extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6761328171051515221L;

	@Override
	public boolean equalsId(Object o) {
		if ((o instanceof PickupSchedule)
				&& ((PickupSchedule) o).getId().equals(this.id)) {
			return true;
		}

		return false;
	}

	@Transient
	public String getTimeRangeLabel() {
		return beginHour + ":" + beginMinute + "-" + endHour + ":" + endMinute;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id = 0L;
	@Enumerated
	private DAY_OF_WEEK dayOfWeek;
	@Column(nullable = false, columnDefinition = "bit(1) DEFAULT 0")
	private Boolean isAvailable = Boolean.FALSE;
	@Column(nullable = false)
	private String beginHour = "16";
	@Column(nullable = false)
	private String beginMinute = "00";
	@Column(nullable = false)
	private String endHour = "22";
	@Column(nullable = false)
	private String endMinute = "00";

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public DAY_OF_WEEK getDayOfWeek() {
		return dayOfWeek;
	}

	public void setDayOfWeek(DAY_OF_WEEK dayOfWeek) {
		this.dayOfWeek = dayOfWeek;
	}

	
	
	public Boolean getIsAvailable() {
		return isAvailable;
	}

	public void setIsAvailable(Boolean isAvailable) {
		this.isAvailable = isAvailable;
	}

	public String getBeginHour() {
		return beginHour;
	}

	public void setBeginHour(String beginHour) {
		this.beginHour = beginHour;
	}

	public String getBeginMinute() {
		return beginMinute;
	}

	public void setBeginMinute(String beginMinute) {
		this.beginMinute = beginMinute;
	}

	public String getEndHour() {
		return endHour;
	}

	public void setEndHour(String endHour) {
		this.endHour = endHour;
	}

	public String getEndMinute() {
		return endMinute;
	}

	public void setEndMinute(String endMinute) {
		this.endMinute = endMinute;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((beginHour == null) ? 0 : beginHour.hashCode());
		result = prime * result
				+ ((beginMinute == null) ? 0 : beginMinute.hashCode());
		result = prime * result
				+ ((dayOfWeek == null) ? 0 : dayOfWeek.hashCode());
		result = prime * result + ((endHour == null) ? 0 : endHour.hashCode());
		result = prime * result
				+ ((endMinute == null) ? 0 : endMinute.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PickupSchedule other = (PickupSchedule) obj;
		if (beginHour == null) {
			if (other.beginHour != null)
				return false;
		} else if (!beginHour.equals(other.beginHour))
			return false;
		if (beginMinute == null) {
			if (other.beginMinute != null)
				return false;
		} else if (!beginMinute.equals(other.beginMinute))
			return false;
		if (dayOfWeek != other.dayOfWeek)
			return false;
		if (endHour == null) {
			if (other.endHour != null)
				return false;
		} else if (!endHour.equals(other.endHour))
			return false;
		if (endMinute == null) {
			if (other.endMinute != null)
				return false;
		} else if (!endMinute.equals(other.endMinute))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "PickupSchedule [id=" + id + ", dayOfWeek=" + dayOfWeek
				+ ", beginHour=" + beginHour + ", beginMinute=" + beginMinute
				+ ", endHour=" + endHour + ", endMinute=" + endMinute + "]";
	}


	
}
